package cn.da.shuai.cool.system.api.controller;

import cn.da.shuai.cool.common.entity.R;
import cn.da.shuai.cool.system.model.entity.role.CoolRole;
import cn.da.shuai.cool.system.model.entity.role.SearchRoleVo;
import cn.da.shuai.cool.system.model.entity.role.UpdateRoleVo;
import cn.da.shuai.cool.system.service.service.ICoolRoleService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/role")
@Tag(name = "角色管理", description = "角色管理相关接口")
public class CoolRoleController {

    private final ICoolRoleService roleService;

    public CoolRoleController(ICoolRoleService roleService) {
        this.roleService = roleService;
    }

    @Operation(summary = "分页查询角色列表")
    @GetMapping("/page")
    public R<IPage<CoolRole>> pageList(SearchRoleVo searchRoleVo) {
        return R.ok(roleService.getPage(searchRoleVo));
    }

    @Operation(summary = "新增角色")
    @PostMapping
    public R<Void> saveRole(@RequestBody UpdateRoleVo updateRoleVo) {
        roleService.saveRole(updateRoleVo);
        return R.ok();
    }

    @Operation(summary = "更新角色")
    @PutMapping
    public R<Void> updateRole(@RequestBody UpdateRoleVo updateRoleVo) {
        roleService.updateRole(updateRoleVo);
        return R.ok();
    }

    @Operation(summary = "删除角色")
    @DeleteMapping("/{id}")
    public R<Void> deleteRole(@PathVariable Integer id) {
        roleService.deleteRole(id);
        return R.ok();
    }

    @Operation(summary = "获取所有角色")
    @GetMapping("/list")
    public R<List<CoolRole>> listAllRoles() {
        return R.ok(roleService.getList(CoolRole.class));
    }
}